﻿using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AutoMapper;
using LiteGrid.Mvc.Results;
using LiteGrid.Mvc.Sample.Domain;
using LiteGrid.Mvc.Sample.Models;

namespace LiteGrid.Mvc.Sample.Controllers
{
    public class PartController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

		[HttpGet]
		public ActionResult Data()
		{
			var models = from p in PartRepository.GetParts()
			             select Mapper.Map<Part, PartViewModel>(p);
			return new LiteGridJsonResult<PartViewModel>(models.ToArray());
		}

		public ActionResult Save(EditedPartViewModel[] parts)
		{
			//TODO: Actually apply the updates to the repository. 
			return new LiteGridJsonResult<PartViewModel>(parts);
		}
    }
}
